package com.wangyu.talents.web.system.user.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.wangyu.talents.core.entity.DataEntity;
import java.util.Date;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.RandomStringUtils;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 系统用户实体
 *
 * @author wangyu
 * @Date 2018-08-31 23:50
 */
public class User extends DataEntity<User> {

  private static final long serialVersionUID = 4676811174592954605L;
  public static final String EMAIL_PATTERN = "^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|\\.|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.?";

  /**
   * 正常状态
   */
  public static final Integer STATUS_NORMAL = 0;

  /**
   * 锁定状态
   */
  public static final Integer STATUS_LOCK = 1;

  /**
   * 真实姓名
   */
  @Length(max = 30, message = "真实姓名内容不超过120字符")
  private String trueName;

  /**
   * 昵称
   */
  @Length(max = 30, message = "昵称内容不超过120字符")
  private String nickName;

  /**
   * 登陆名
   */
  @NotNull(message = "用户名不能为空")
  @Length(max = 30, message = "登陆名内容不超过120字符")
  private String loginName;

  /**
   * 性别 0:男，1:女
   */
  private Integer sex = 0;

  /**
   * 年龄
   */
  @Max(value = 120, message = "您输入的年龄不能超过120岁")
  private Integer age;

  /**
   * 出身日期
   */
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  private Date birthDay;

  /**
   * 头像
   */
  private String picture;

  /**
   * 地址
   */
  @Length(max = 50, message = "地址不能超过100字符")
  private String address;

  /**
   * 电话
   */
  @Length(max = 11)
  private String phone;

  /**
   * 密码
   */
  @Length(max = 50, message = "密码长度不能超过100字符")
  @JSONField(serialize = false)
  private String password;

  /**
   * 加密密码时使用的种子
   */
  @JSONField(serialize = false)
  private String salt;

  /**
   * 邮箱
   */
  @Length(max = 30)
  private String email;

  /**
   * 身份证号
   */
  @Length(max = 18)
  private String idCard;

  /**
   * 状态
   */
  private Integer status = User.STATUS_NORMAL;

  /**
   * 用户类型 1：前台用户  ，0：后台用户 ,100:root
   */
  private Integer type;

  /**
   * 备注
   */
  @JSONField(serialize = false)
  @Length(max = 100)
  private String remark;

  public String getTrueName() {
    return trueName;
  }

  public void setTrueName(String trueName) {
    this.trueName = trueName;
  }

  public String getNickName() {
    return nickName;
  }

  public void setNickName(String nickName) {
    this.nickName = nickName;
  }

  public String getLoginName() {
    return loginName;
  }

  public void setLoginName(String loginName) {
    this.loginName = loginName;
  }

  public Integer getSex() {
    return sex;
  }

  public void setSex(Integer sex) {
    this.sex = sex;
  }

  public Integer getAge() {
    return age;
  }

  public void setAge(Integer age) {
    this.age = age;
  }

  public Date getBirthDay() {
    return birthDay;
  }

  public void setBirthDay(Date birthDay) {
    this.birthDay = birthDay;
  }

  public String getPicture() {
    return picture;
  }

  public void setPicture(String picture) {
    this.picture = picture;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getPhone() {
    return phone;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getSalt() {
    return salt;
  }

  public void setSalt(String salt) {
    this.salt = salt;
  }

  public String getEmail() {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getIdCard() {
    return idCard;
  }

  public void setIdCard(String idCard) {
    this.idCard = idCard;
  }

  public Integer getStatus() {
    return status;
  }

  public void setStatus(Integer status) {
    this.status = status;
  }

  public Integer getType() {
    return type;
  }

  public void setType(Integer type) {
    this.type = type;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  /**
   * 生成新的种子
   */
  public void randomSalt() {
    setSalt(RandomStringUtils.randomAlphanumeric(10));
  }


}
